import path from 'path'
import webpack from 'webpack'
import routes from './src/route'
import env from './env'

export default {
  mode: 'spa',
  srcDir: 'src/',
  /*
   ** Headers of the page
   */
  head: {
    title: '营加科技管理后台',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      {
        hid: 'description',
        name: 'description',
        content: process.env.npm_package_description || ''
      }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/logo.ico' },
      {
        type: 'text/css',
        rel: 'stylesheet',
        href: '//at.alicdn.com/t/font_2053999_4eyx4p9twur.css'
      }
    ],
    script: [
      {
        src:
          'https://webapi.amap.com/maps?v=1.4.15&key=eee62df3de8f69084383373de805d95b&plugin=AMap.Geocoder,AMap.Autocomplete,AMap.PlaceSearch'
      }
    ]
  },
  server: {
    port: 3600, // default: 3000
    host: '0.0.0.0' // default: localhost,
  },
  // modern: process.env.NODE_ENV === 'production',
  /*
   ** Customize the progress-bar color
   */
  loading: { color: '#1890ff' },
  /*
   ** Global CSS
   */
  css: [
    'ant-design-vue/dist/antd.less',
    'viewerjs/dist/viewer.css',
    '@/styles/reset.css',
    '@/styles/theme.less',
    '@/styles/style.less',
    '@/styles/layout.less',
    '@/styles/flex.less'
  ],
  /*
   ** Plugins to load before mounting the App
   */
  plugins: [
    '@/plugins/antd-ui',
    '@/plugins/axios',
    '@/plugins/api',
    '@/plugins/ClientInit.js',
    '@/plugins/components',
    '@/plugins/directives',
    '@/plugins/filters',
    '@/plugins/mixins',
    '@/plugins/persistedstate.js',
    '@/plugins/vue-map.js'
  ],
  /*
   ** Nuxt.js modules
   */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    // '@nuxtjs/pwa',
    '@nuxtjs/eslint-module',
    [
      'nuxt-i18n',
      {
        locales: ['zh_CN', 'zh_TW', 'en_US'],
        defaultLocale: 'zh_CN',
        strategy: 'no_prefix',
        vueI18nLoader: false,
        vueI18n: {
          fallbackLocale: 'zh_CN',
          messages: {
            zh_CN: require('./locales/zh_CN.json'),
            zh_TW: require('./locales/zh_TW.json'),
            en_US: require('./locales/en_US.json')
          }
        },
        vuex: false
      }
    ]
  ],
  /*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: {
    baseURL: env.baseURL,
    proxy: true,
    credentials: true
  },
  proxy: {
    '/api': {
      target: env.baseURL
    },
    '/adminapi': {
      target: env.baseURL
    },
    '/addons': {
      target: env.baseURL
    },
    '/retailadmin': {
      target: env.baseURL
    }
  },
  /**
   * routers
   */
  router: {
    // base: '/admin/',
    middleware: ['permisssions'],
    extendRoutes(nuxtRoutes, resolve) {
      nuxtRoutes.length = 0
      nuxtRoutes.push(...routes)
    }
  },
  watchers: {
    webpack: {
      aggregateTimeout: 300,
      poll: 1000
    }
  },
  /*
   ** Build configuration
   */
  build: {
    parallel: true,
    friendlyErrors: false,
    loaders: {
      less: {
        lessOptions: {
          modifyVars: {
            hack: `true; @import "${path.resolve(
              __dirname,
              './src/assets/styles/theme.less'
            )}"`
          },
          javascriptEnabled: true
        }
      }
    },
    plugins: [
      // Ignore all locale files of moment.js
      new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
      new webpack.ProvidePlugin({
        _: 'lodash'
      })
    ],
    /*
     ** You can extend webpack config here
     */
    extend(config, ctx) {}
  }
}
